using System;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Coding4Fun.Phone.Controls
{
	public class MovementMonitor
	{
		private EventHandler<MovementMonitorEventArgs> eventHandler_0;
		protected Rectangle Monitor;
		private double double_0;
		private double double_1;
		public event EventHandler<MovementMonitorEventArgs> Movement
		{
			add
			{
				EventHandler<MovementMonitorEventArgs> eventHandler = this.eventHandler_0;
				EventHandler<MovementMonitorEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<MovementMonitorEventArgs> eventHandler3 = (EventHandler<MovementMonitorEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler<MovementMonitorEventArgs>>(ref this.eventHandler_0, eventHandler3, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
			remove
			{
				EventHandler<MovementMonitorEventArgs> eventHandler = this.eventHandler_0;
				EventHandler<MovementMonitorEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<MovementMonitorEventArgs> eventHandler3 = (EventHandler<MovementMonitorEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler<MovementMonitorEventArgs>>(ref this.eventHandler_0, eventHandler3, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
		}
		public void MonitorControl(Panel panel)
		{
			Rectangle rectangle = new Rectangle();
			rectangle.set_Fill(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)));
			this.Monitor = rectangle;
			this.Monitor.SetValue(Grid.RowSpanProperty, 2147483646);
			this.Monitor.SetValue(Grid.ColumnSpanProperty, 2147483646);
			this.Monitor.add_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.method_1));
			this.Monitor.add_ManipulationDelta(new EventHandler<ManipulationDeltaEventArgs>(this.method_0));
			panel.get_Children().Add(this.Monitor);
		}
		private void method_0(object sender, ManipulationDeltaEventArgs e)
		{
			if (this.eventHandler_0 != null)
			{
				this.eventHandler_0.Invoke(this, new MovementMonitorEventArgs
				{
					X = this.double_0 + e.get_CumulativeManipulation().get_Translation().get_X(),
					Y = this.double_1 + e.get_CumulativeManipulation().get_Translation().get_Y()
				});
			}
			e.set_Handled(true);
		}
		private void method_1(object sender, ManipulationStartedEventArgs e)
		{
			this.double_0 = e.get_ManipulationOrigin().get_X();
			this.double_1 = e.get_ManipulationOrigin().get_Y();
			if (this.eventHandler_0 != null)
			{
				this.eventHandler_0.Invoke(this, new MovementMonitorEventArgs
				{
					X = this.double_0,
					Y = this.double_1
				});
			}
			e.set_Handled(true);
		}
	}
}
